﻿Public Class perSegmento
    Inherits perAcessoBD

    Public Function retornarSegmentos(ByVal iCodSegmento As Int32, ByVal iTipoMercado As Int32) As DataTable
        Dim sSql As String

        sSql = "SELECT codSegmento, convert(nvarchar(2),codSegmento ) + ' - ' + segmento as segmento" & Environment.NewLine &
               "  FROM Segmento " & Environment.NewLine &
               " WHERE 1=1 " & Environment.NewLine
        If iCodSegmento > 0 Then
            sSql &= "  AND codSegmento = @codSegmento" & Environment.NewLine
        End If
        If iTipoMercado >= 0 Then
            sSql &= "  AND mercado = @mercado" & Environment.NewLine
        End If

        With MyBase.SQLCmd.Parameters
            .Clear()

            If iCodSegmento > 0 Then
                .AddWithValue("@codSegmento", iCodSegmento)
            End If

            If iTipoMercado >= 0 Then
                .AddWithValue("mercado", iTipoMercado)
            End If
        End With

        Return MyBase.executarConsulta(sSql)

    End Function

End Class
